// #include <NTPClient.h>

// #include <WiFiManager.h>
// #include <strings_en.h>
// #include <wm_consts_en.h>
// #include <wm_strings_en.h>
// #include <wm_strings_es.h>

// #include <uRTCLib.h>

// #include <ArduinoWiFiServer.h>
// #include <BearSSLHelpers.h>
// #include <CertStoreBearSSL.h>
// #include <ESP8266WiFi.h>
// #include <ESP8266WiFiAP.h>
// #include <ESP8266WiFiGeneric.h>
// #include <ESP8266WiFiGratuitous.h>
// #include <ESP8266WiFiMulti.h>
// #include <ESP8266WiFiSTA.h>
// #include <ESP8266WiFiScan.h>
// #include <ESP8266WiFiType.h>
// #include <WiFiClient.h>
// #include <WiFiClientSecure.h>
// #include <WiFiClientSecureBearSSL.h>
// #include <WiFiServer.h>
// #include <WiFiServerSecure.h>
// #include <WiFiServerSecureBearSSL.h>
// #include <WiFiUdp.h>

// #include <Ticker.h>

// #include <ESP8266WebServer-impl.h>
// #include <ESP8266WebServer.h>
// #include <ESP8266WebServerSecure.h>
// #include <Parsing-impl.h>
// #include <Uri.h>

// #include <DNSServer.h>

/**********************************************************************
  项目名称/Project          : HUB08 模块驱动
  程序名称/Program name     :
  团队/Team                :
  作者/Author              :
  日期/Date（YYYYMMDD）     : 20230630
  程序目的/Purpose          :
***********************************************************************/
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <NTPClient.h>
#include <Ticker.h>
#include "uRTCLib.h"
#include "gpio.h"

typedef bool bit;
typedef uint8_t uchar;

//==================================================================
#define STATE_OFF_MYLIGHT 99  // 不亮
#define STATE_MAX_MYLIGHT 12  // 最亮，最大值=12*20=240 < 256
#define STATE_MIN_MYLIGHT 0   // 最暗

#define STATE_MAX_MYDISPLAY 3  // 显示演示行数3+1=4
#define STATE_MAX_MYALWAYS 4   // 一直演示状态显示演示总行数4+1=5
#define STATE_MAX_MYHELP 18    // 显示帮助行数3+1=4

#define STATE_MAX_MYSTYTE3 2  // 最大 MyStyte3
//==================================================================

Ticker timer1;  // ESP8266定时器
uRTCLib rtc;    // default: DS3231  0x68(0110 1000) 八位地址为 = 0xd0(1101 0000)>>1
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "ntp.aliyun.com", 8 * 60 * 60, 30 * 60 * 1000);

void (*resetFunc)(void) = 0;

// Variables to save date and time
String formattedDate;
String dayStamp;

int ledPin = 2;  // D4(GPIO2) of ESP8266-01S

//==================================================================
const uchar Tablehub[] = {
  // 0(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) 7(7) 8(8) 9(9) 10(:) 11( )
  0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00,  // 0
  0x00, 0x00, 0x18, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00,  // 1
  0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x60, 0x60, 0x7e, 0x00, 0x00,  // 2
  0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x06, 0x1c, 0x06, 0x06, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00,  // 3
  0x00, 0x00, 0x0c, 0x1c, 0x3c, 0x2c, 0x6c, 0x6c, 0x6c, 0x6c, 0x7e, 0x0c, 0x0c, 0x0c, 0x00, 0x00,  // 4
  0x00, 0x00, 0x7e, 0x60, 0x60, 0x60, 0x7c, 0x66, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3c, 0x00, 0x00,  // 5
  0x00, 0x00, 0x3c, 0x60, 0x60, 0x60, 0x60, 0x7c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00,  // 6
  0x00, 0x00, 0x7e, 0x06, 0x06, 0x0c, 0x0c, 0x0c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00,  // 7
  0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00,  // 8
  0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3e, 0x06, 0x06, 0x66, 0x66, 0x3c, 0x00, 0x00,  // 9
  0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00,  // 10:	“：冒号”
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // 11:[ ]	空
};

const uchar TableTempS[] = {
  // 温度十位
  // 0(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) 7(7) 8(8) 9(9) 10( ) 11( )
  0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x06, 0x00, 0x00, /*"0",0*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, /*"1",1*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x01, 0x02, 0x04, 0x04, 0x08, 0x0F, 0x00, 0x00, /*"2",2*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x01, 0x06, 0x01, 0x09, 0x09, 0x06, 0x00, 0x00, /*"3",3*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x05, 0x05, 0x09, 0x0F, 0x01, 0x01, 0x00, 0x00, /*"4",4*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x08, 0x0E, 0x09, 0x01, 0x09, 0x09, 0x06, 0x00, 0x00, /*"5",5*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x08, 0x0E, 0x09, 0x09, 0x09, 0x06, 0x00, 0x00, /*"6",6*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x01, 0x01, 0x02, 0x02, 0x02, 0x04, 0x04, 0x04, 0x00, 0x00, /*"7",7*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x09, 0x06, 0x09, 0x09, 0x09, 0x06, 0x00, 0x00, /*"8",8*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x09, 0x07, 0x01, 0x09, 0x09, 0x06, 0x00, 0x00, /*"9",9*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" ",10*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" ",11*/
};

const uchar TableTempG[] = {
  // 温度个位
  // 0(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) 7(7) 8(8) 9(9) 10(c) 11( )
  0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x48 + 1, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x30, 0x00, 0x00, /*"0",0*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x30 + 1, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, /*"1",1*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x48 + 1, 0x48, 0x08, 0x10, 0x20, 0x20, 0x40, 0x78, 0x00, 0x00, /*"2",2*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x48 + 1, 0x48, 0x08, 0x30, 0x08, 0x48, 0x48, 0x30, 0x00, 0x00, /*"3",3*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18 + 1, 0x18, 0x28, 0x28, 0x48, 0x7C, 0x08, 0x08, 0x00, 0x00, /*"4",4*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x40 + 1, 0x40, 0x70, 0x48, 0x08, 0x48, 0x48, 0x30, 0x00, 0x00, /*"5",5*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x48 + 1, 0x48, 0x40, 0x70, 0x48, 0x48, 0x48, 0x30, 0x00, 0x00, /*"6",6*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x08 + 1, 0x08, 0x10, 0x10, 0x10, 0x20, 0x20, 0x20, 0x00, 0x00, /*"7",7*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x48 + 1, 0x48, 0x48, 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, 0x00, /*"8",8*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x48 + 1, 0x48, 0x48, 0x38, 0x08, 0x48, 0x48, 0x30, 0x00, 0x00, /*"9",9*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x80, 0x38, 0x40, 0x40, 0x40, 0x40, 0x38, 0x00, 0x00,     /*"c",10*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,     /*" ",11*/
};

const uchar TableWeek[] = {
  // 一(0) 二(1) 三(2) 四(3) 五(4) 六(5) 日(6)
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xF8, 0xFF, 0xFC, 0xF8, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"一",0*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xC0,
  0x1F, 0x80, 0x10, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x7F, 0xF8, 0xF8, 0x08, 0x00, 0x00, 0x00, 0x00, /*"二",1*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x0F, 0x00,
  0x00, 0x00, 0x0F, 0x80, 0x0C, 0x00, 0x00, 0x00, 0x0F, 0xF8, 0xF0, 0x04, 0x00, 0x00, 0x00, 0x00, /*"三",2*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF8,
  0xFF, 0x1C, 0xC9, 0x18, 0xD9, 0x98, 0x40, 0x10, 0x3F, 0xB0, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, /*"四",3*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x1F, 0xC0, 0x1F, 0x00, 0x02, 0x00,
  0x07, 0xC0, 0x3C, 0xC0, 0x0C, 0xC0, 0x09, 0x80, 0x1F, 0xF8, 0xFE, 0x38, 0x00, 0x00, 0x00, 0x00, /*"五",4*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x06, 0x00, 0x02, 0x00, 0x00, 0xFC,
  0x1F, 0xFC, 0xFC, 0x00, 0x10, 0x00, 0x18, 0xE0, 0x30, 0x70, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, /*"六",5*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0xE3, 0x00, 0xC3, 0x00,
  0xFB, 0x00, 0xC3, 0x00, 0xC3, 0x00, 0xFB, 0x00, 0x07, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, /*"日",6*/
};

const uchar TableYanShi[] = {
  // 数(0) 字(1) 时(2) 钟(3) --------- 0
  0x08, 0x20, 0x49, 0x20, 0x2A, 0x20, 0x08, 0x3E, 0xFF, 0x44, 0x2A, 0x44, 0x49, 0x44, 0x88, 0xA4,
  0x10, 0x28, 0xFE, 0x28, 0x22, 0x10, 0x42, 0x10, 0x64, 0x28, 0x18, 0x28, 0x34, 0x44, 0xC2, 0x82, /*"数",0*/
  0x02, 0x00, 0x01, 0x00, 0x7F, 0xFE, 0x40, 0x02, 0x80, 0x04, 0x1F, 0xE0, 0x00, 0x40, 0x00, 0x80,
  0x01, 0x00, 0xFF, 0xFE, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x05, 0x00, 0x02, 0x00, /*"字",1*/
  0x00, 0x08, 0x00, 0x08, 0x7C, 0x08, 0x44, 0x08, 0x45, 0xFE, 0x44, 0x08, 0x44, 0x08, 0x7C, 0x08,
  0x44, 0x88, 0x44, 0x48, 0x44, 0x48, 0x44, 0x08, 0x7C, 0x08, 0x44, 0x08, 0x00, 0x28, 0x00, 0x10, /*"时",2*/
  0x10, 0x20, 0x10, 0x20, 0x3C, 0x20, 0x20, 0x20, 0x41, 0xFC, 0xBD, 0x24, 0x11, 0x24, 0x11, 0x24,
  0xFD, 0x24, 0x11, 0xFC, 0x11, 0x24, 0x10, 0x20, 0x14, 0x20, 0x18, 0x20, 0x10, 0x20, 0x00, 0x20, /*"钟",3*/
  // 走(0) 时(1) 精(2) 准(3) ---------- 1
  0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3F, 0xF8, 0x01, 0x00, 0x01, 0x00, 0xFF, 0xFE, 0x01, 0x00,
  0x01, 0x00, 0x11, 0x00, 0x11, 0xF8, 0x11, 0x00, 0x11, 0x00, 0x29, 0x00, 0x47, 0xFE, 0x80, 0x00, /*"走",0*/
  0x00, 0x08, 0x00, 0x08, 0x7C, 0x08, 0x44, 0x08, 0x45, 0xFE, 0x44, 0x08, 0x44, 0x08, 0x7C, 0x08,
  0x44, 0x88, 0x44, 0x48, 0x44, 0x48, 0x44, 0x08, 0x7C, 0x08, 0x44, 0x08, 0x00, 0x28, 0x00, 0x10, /*"时",1*/
  0x10, 0x20, 0x10, 0x20, 0x95, 0xFE, 0x54, 0x20, 0x58, 0xFC, 0x10, 0x20, 0xFD, 0xFE, 0x30, 0x00,
  0x38, 0xFC, 0x54, 0x84, 0x54, 0xFC, 0x90, 0x84, 0x10, 0xFC, 0x10, 0x84, 0x10, 0x94, 0x10, 0x88, /*"精",2*/
  0x01, 0x40, 0x41, 0x20, 0x21, 0x20, 0x23, 0xFE, 0x02, 0x20, 0x16, 0x20, 0x1B, 0xFC, 0x12, 0x20,
  0x22, 0x20, 0x23, 0xFC, 0xE2, 0x20, 0x22, 0x20, 0x22, 0x20, 0x23, 0xFE, 0x22, 0x00, 0x02, 0x00, /*"准",3*/
  // 重(0) 力(1) 感(2) 应(3) ------------2
  0x00, 0x10, 0x00, 0xF8, 0x3F, 0x00, 0x01, 0x00, 0xFF, 0xFE, 0x01, 0x00, 0x1F, 0xF0, 0x11, 0x10,
  0x1F, 0xF0, 0x11, 0x10, 0x1F, 0xF0, 0x01, 0x00, 0x3F, 0xF8, 0x01, 0x00, 0xFF, 0xFE, 0x00, 0x00, /*"重",0*/
  0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x7F, 0xF8, 0x02, 0x08, 0x02, 0x08, 0x02, 0x08,
  0x02, 0x08, 0x04, 0x08, 0x04, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x88, 0x20, 0x50, 0x40, 0x20, /*"力",1*/
  0x00, 0x28, 0x00, 0x24, 0x3F, 0xFE, 0x20, 0x20, 0x2F, 0xA4, 0x20, 0x24, 0x2F, 0xA8, 0x28, 0x98,
  0x28, 0x92, 0x4F, 0xAA, 0x40, 0x46, 0x80, 0x82, 0x01, 0x00, 0x48, 0x84, 0x48, 0x12, 0x87, 0xF2, /*"感",2*/
  0x01, 0x00, 0x00, 0x80, 0x3F, 0xFE, 0x20, 0x00, 0x20, 0x00, 0x21, 0x04, 0x28, 0x84, 0x24, 0x84,
  0x24, 0x48, 0x22, 0x48, 0x22, 0x10, 0x22, 0x10, 0x40, 0x20, 0x40, 0x40, 0x9F, 0xFE, 0x00, 0x00, /*"应",3*/
  // 昼(0) 亮(1) 夜(2) 暗(3)------------3
  0x00, 0x00, 0x1F, 0xF8, 0x10, 0x08, 0x10, 0x08, 0x1F, 0xF8, 0x10, 0x40, 0x10, 0x20, 0x20, 0x10,
  0x2F, 0xE8, 0x48, 0x26, 0x8F, 0xE0, 0x08, 0x20, 0x0F, 0xE0, 0x00, 0x00, 0x7F, 0xFC, 0x00, 0x00, /*"昼",0*/
  0x02, 0x00, 0x01, 0x00, 0x7F, 0xFC, 0x00, 0x00, 0x1F, 0xF0, 0x10, 0x10, 0x1F, 0xF0, 0x00, 0x00,
  0x7F, 0xFE, 0x40, 0x02, 0x8F, 0xE4, 0x08, 0x20, 0x08, 0x20, 0x10, 0x22, 0x20, 0x22, 0xC0, 0x1E, /*"亮",1*/
  0x02, 0x00, 0x01, 0x00, 0xFF, 0xFE, 0x08, 0x80, 0x08, 0x80, 0x10, 0xF8, 0x11, 0x08, 0x31, 0x48,
  0x52, 0x28, 0x95, 0x10, 0x11, 0x10, 0x10, 0xA0, 0x10, 0x40, 0x10, 0xA0, 0x11, 0x18, 0x16, 0x06, /*"夜",2*/
  0x00, 0x80, 0x00, 0x40, 0x7B, 0xFC, 0x48, 0x00, 0x49, 0x08, 0x48, 0x90, 0x4F, 0xFE, 0x78, 0x00,
  0x49, 0xF8, 0x49, 0x08, 0x49, 0x08, 0x49, 0xF8, 0x79, 0x08, 0x49, 0x08, 0x01, 0xF8, 0x01, 0x08, /*"暗",3*/
  // 1(0) 5(1) 0(2) 元(3) /(4) 台(5) ---4
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x18, 0x42, 0x24, 0x42, 0x42, 0x02, 0x42, 0x04, 0x42, /*"3",0*/
  0x18, 0x42, 0x04, 0x42, 0x02, 0x42, 0x42, 0x42, 0x42, 0x24, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, /*"0",1*/
  0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x18, 0x00, 0x24, 0x00, 0x42, 0xFF, 0x42, 0x04, 0x42, 0x04, /*"0",2*/
  0x42, 0x04, 0x42, 0x04, 0x42, 0x08, 0x42, 0x08, 0x24, 0x10, 0x18, 0x20, 0x00, 0x40, 0x00, 0x80, /*"元",3*/
  0x00, 0x00, 0xF8, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x04, 0xFE, 0x04, 0x40, 0x08, 0x40, 0x08, /*"元",3*/
  0x40, 0x10, 0x40, 0x10, 0x40, 0x10, 0x42, 0x20, 0x42, 0x20, 0x42, 0x40, 0x3E, 0x40, 0x00, 0x00, /*"/",4*/
  0x02, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08, 0x20, 0x10, 0x10, 0x20, 0x08, 0x7F, 0xFC, 0x20, 0x04,
  0x00, 0x00, 0x1F, 0xF0, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0, 0x10, 0x10, /*"台",5*/
  // 自(0) 动(1) 亮(2) 度(3) ----------- 5
  0x02, 0x00, 0x01, 0x00, 0x7F, 0xFC, 0x00, 0x00, 0x1F, 0xF0, 0x10, 0x10, 0x1F, 0xF0, 0x00, 0x00,
  0x7F, 0xFE, 0x40, 0x02, 0x8F, 0xE4, 0x08, 0x20, 0x08, 0x20, 0x10, 0x22, 0x20, 0x22, 0xC0, 0x1E, /*"亮",2*/
  0x01, 0x00, 0x00, 0x80, 0x3F, 0xFE, 0x22, 0x20, 0x22, 0x20, 0x3F, 0xFC, 0x22, 0x20, 0x22, 0x20,
  0x23, 0xE0, 0x20, 0x00, 0x2F, 0xF0, 0x24, 0x10, 0x42, 0x20, 0x41, 0xC0, 0x86, 0x30, 0x38, 0x0E, /*"度",3*/
  0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x1F, 0xF0, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0,
  0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0, 0x10, 0x10, /*"自",0*/
  0x00, 0x40, 0x00, 0x40, 0x7C, 0x40, 0x00, 0x40, 0x01, 0xFC, 0x00, 0x44, 0xFE, 0x44, 0x20, 0x44,
  0x20, 0x44, 0x20, 0x84, 0x48, 0x84, 0x44, 0x84, 0xFD, 0x04, 0x45, 0x04, 0x02, 0x28, 0x04, 0x10, /*"动",1*/
  // 恒(0) 定(1) 亮(2) 度(3) ----------- 6
  0x02, 0x00, 0x01, 0x00, 0x7F, 0xFC, 0x00, 0x00, 0x1F, 0xF0, 0x10, 0x10, 0x1F, 0xF0, 0x00, 0x00,
  0x7F, 0xFE, 0x40, 0x02, 0x8F, 0xE4, 0x08, 0x20, 0x08, 0x20, 0x10, 0x22, 0x20, 0x22, 0xC0, 0x1E, /*"亮",2*/
  0x01, 0x00, 0x00, 0x80, 0x3F, 0xFE, 0x22, 0x20, 0x22, 0x20, 0x3F, 0xFC, 0x22, 0x20, 0x22, 0x20,
  0x23, 0xE0, 0x20, 0x00, 0x2F, 0xF0, 0x24, 0x10, 0x42, 0x20, 0x41, 0xC0, 0x86, 0x30, 0x38, 0x0E, /*"度",3*/
  0x10, 0x00, 0x13, 0xFE, 0x10, 0x00, 0x10, 0x00, 0x19, 0xFC, 0x55, 0x04, 0x51, 0x04, 0x51, 0xFC,
  0x91, 0x04, 0x11, 0x04, 0x11, 0xFC, 0x11, 0x04, 0x10, 0x00, 0x10, 0x00, 0x13, 0xFE, 0x10, 0x00, /*"恒",0*/
  0x02, 0x00, 0x01, 0x00, 0x7F, 0xFE, 0x40, 0x02, 0x80, 0x04, 0x00, 0x00, 0x3F, 0xF8, 0x01, 0x00,
  0x01, 0x00, 0x11, 0x00, 0x11, 0xF8, 0x11, 0x00, 0x11, 0x00, 0x29, 0x00, 0x47, 0xFE, 0x80, 0x00, /*"定",1*/
  // 亮(0) 度(1)  (2)  (3) 高 ---------- 7
  0x02, 0x00, 0x01, 0x00, 0x7F, 0xFC, 0x00, 0x00, 0x1F, 0xF0, 0x10, 0x10, 0x1F, 0xF0, 0x00, 0x00,
  0x7F, 0xFE, 0x40, 0x02, 0x8F, 0xE4, 0x08, 0x20, 0x08, 0x20, 0x10, 0x22, 0x20, 0x22, 0xC0, 0x1E, /*"亮",0*/
  0x01, 0x00, 0x00, 0x80, 0x3F, 0xFE, 0x22, 0x20, 0x22, 0x20, 0x3F, 0xFC, 0x22, 0x20, 0x22, 0x20,
  0x23, 0xE0, 0x20, 0x00, 0x2F, 0xF0, 0x24, 0x10, 0x42, 0x20, 0x41, 0xC0, 0x86, 0x30, 0x38, 0x0E, /*"度",1*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" ",2*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" ",3*/
  0x02, 0x00, 0x01, 0x00, 0xFF, 0xFE, 0x00, 0x00, 0x0F, 0xE0, 0x08, 0x20, 0x08, 0x20, 0x0F, 0xE0,
  0x00, 0x00, 0x7F, 0xFC, 0x40, 0x04, 0x4F, 0xE4, 0x48, 0x24, 0x48, 0x24, 0x4F, 0xE4, 0x40, 0x0C, /*"高",4*/
  // 亮(0) 度(1)  (2)  (3) 低------------- 8
  0x02, 0x00, 0x01, 0x00, 0x7F, 0xFC, 0x00, 0x00, 0x1F, 0xF0, 0x10, 0x10, 0x1F, 0xF0, 0x00, 0x00,
  0x7F, 0xFE, 0x40, 0x02, 0x8F, 0xE4, 0x08, 0x20, 0x08, 0x20, 0x10, 0x22, 0x20, 0x22, 0xC0, 0x1E, /*"亮",0*/
  0x01, 0x00, 0x00, 0x80, 0x3F, 0xFE, 0x22, 0x20, 0x22, 0x20, 0x3F, 0xFC, 0x22, 0x20, 0x22, 0x20,
  0x23, 0xE0, 0x20, 0x00, 0x2F, 0xF0, 0x24, 0x10, 0x42, 0x20, 0x41, 0xC0, 0x86, 0x30, 0x38, 0x0E, /*"度",1*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" ",2*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" ",3*/
  0x08, 0x08, 0x08, 0x3C, 0x0B, 0xE0, 0x12, 0x20, 0x12, 0x20, 0x32, 0x20, 0x32, 0x20, 0x53, 0xFE,
  0x92, 0x20, 0x12, 0x10, 0x12, 0x10, 0x12, 0x12, 0x12, 0x0A, 0x12, 0x8A, 0x13, 0x26, 0x12, 0x12, /*"低",4*/
  // 午(0) 休(1)  (2)  (3) 开(4) ------- 9
  0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x1F, 0xF8, 0x11, 0x00, 0x21, 0x00, 0x41, 0x00, 0x01, 0x00,
  0x01, 0x00, 0xFF, 0xFE, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, /*"午",0*/
  0x08, 0x40, 0x08, 0x40, 0x08, 0x40, 0x10, 0x40, 0x17, 0xFE, 0x30, 0x40, 0x30, 0xE0, 0x50, 0xE0,
  0x91, 0x50, 0x11, 0x50, 0x12, 0x48, 0x14, 0x44, 0x18, 0x42, 0x10, 0x40, 0x10, 0x40, 0x10, 0x40, /*"休",1*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" ",2*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" ",3*/
  0x00, 0x00, 0x7F, 0xFC, 0x08, 0x20, 0x08, 0x20, 0x08, 0x20, 0x08, 0x20, 0x08, 0x20, 0xFF, 0xFE,
  0x08, 0x20, 0x08, 0x20, 0x08, 0x20, 0x08, 0x20, 0x10, 0x20, 0x10, 0x20, 0x20, 0x20, 0x40, 0x20, /*"开",4*/
  // 午(0) 休(1)  (2)  (3) 关(4) -------- 10
  0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x1F, 0xF8, 0x11, 0x00, 0x21, 0x00, 0x41, 0x00, 0x01, 0x00,
  0x01, 0x00, 0xFF, 0xFE, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, /*"午",0*/
  0x08, 0x40, 0x08, 0x40, 0x08, 0x40, 0x10, 0x40, 0x17, 0xFE, 0x30, 0x40, 0x30, 0xE0, 0x50, 0xE0,
  0x91, 0x50, 0x11, 0x50, 0x12, 0x48, 0x14, 0x44, 0x18, 0x42, 0x10, 0x40, 0x10, 0x40, 0x10, 0x40, /*"休",1*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" ",2*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" ",3*/
  0x10, 0x10, 0x08, 0x10, 0x08, 0x20, 0x00, 0x00, 0x3F, 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
  0xFF, 0xFE, 0x01, 0x00, 0x02, 0x80, 0x02, 0x80, 0x04, 0x40, 0x08, 0x20, 0x30, 0x18, 0xC0, 0x06, /*"关",4*/
  // 富(0) 强(1) 民(2) 主(3) ----------- 11
  0x02, 0x00, 0x01, 0x00, 0x7F, 0xFE, 0x40, 0x02, 0xBF, 0xFC, 0x00, 0x00, 0x1F, 0xF0, 0x10, 0x10,
  0x1F, 0xF0, 0x00, 0x00, 0x3F, 0xF8, 0x21, 0x08, 0x3F, 0xF8, 0x21, 0x08, 0x3F, 0xF8, 0x20, 0x08, /*"富",0*/
  0x00, 0x00, 0xF9, 0xFC, 0x09, 0x04, 0x09, 0x04, 0x09, 0xFC, 0x78, 0x20, 0x40, 0x20, 0x43, 0xFE,
  0x42, 0x22, 0x7A, 0x22, 0x0B, 0xFE, 0x08, 0x20, 0x08, 0x24, 0x08, 0x22, 0x57, 0xFE, 0x20, 0x02, /*"强",1*/
  0x00, 0x00, 0x3F, 0xF8, 0x20, 0x08, 0x20, 0x08, 0x20, 0x08, 0x3F, 0xF8, 0x20, 0x80, 0x20, 0x80,
  0x3F, 0xFC, 0x20, 0x80, 0x20, 0x40, 0x20, 0x40, 0x24, 0x24, 0x28, 0x14, 0x30, 0x0C, 0x20, 0x04, /*"民",2*/
  0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7F, 0xFC, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
  0x3F, 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0xFF, 0xFE, 0x00, 0x00, /*"主",3*/
  // 文(0) 明(1) 和(2) 谐(3)
  0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0xFF, 0xFE, 0x10, 0x10, 0x10, 0x10, 0x08, 0x20, 0x08, 0x20,
  0x04, 0x40, 0x02, 0x80, 0x01, 0x00, 0x02, 0x80, 0x04, 0x40, 0x08, 0x20, 0x30, 0x18, 0xC0, 0x06, /*"文",0*/
  0x00, 0x00, 0x00, 0xFC, 0x7C, 0x84, 0x44, 0x84, 0x44, 0x84, 0x44, 0xFC, 0x7C, 0x84, 0x44, 0x84,
  0x44, 0x84, 0x44, 0xFC, 0x7C, 0x84, 0x44, 0x84, 0x01, 0x04, 0x01, 0x04, 0x02, 0x14, 0x04, 0x08, /*"明",1*/
  0x04, 0x00, 0x0E, 0x00, 0x78, 0x00, 0x08, 0x7C, 0x08, 0x44, 0xFF, 0x44, 0x08, 0x44, 0x18, 0x44,
  0x1C, 0x44, 0x2A, 0x44, 0x2A, 0x44, 0x48, 0x44, 0x88, 0x7C, 0x08, 0x44, 0x08, 0x00, 0x08, 0x00, /*"和",2*/
  0x02, 0x20, 0x22, 0x24, 0x13, 0xA8, 0x12, 0x30, 0x02, 0xA2, 0x03, 0x22, 0xF2, 0x5E, 0x10, 0x80,
  0x13, 0xFC, 0x12, 0x04, 0x12, 0x04, 0x13, 0xFC, 0x16, 0x04, 0x1A, 0x04, 0x13, 0xFC, 0x02, 0x04, /*"谐",3*/
  // 自(0) 由(1) 平(2) 等(3)
  0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x1F, 0xF0, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0,
  0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0, 0x10, 0x10, /*"自",0*/
  0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3F, 0xF8, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08,
  0x21, 0x08, 0x3F, 0xF8, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x3F, 0xF8, 0x20, 0x08, /*"由",1*/
  0x00, 0x00, 0x7F, 0xFC, 0x01, 0x00, 0x01, 0x00, 0x11, 0x10, 0x09, 0x10, 0x09, 0x20, 0x01, 0x00,
  0xFF, 0xFE, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, /*"平",2*/
  0x20, 0x40, 0x3F, 0x7E, 0x48, 0x90, 0x85, 0x08, 0x01, 0x00, 0x3F, 0xF8, 0x01, 0x00, 0x01, 0x00,
  0xFF, 0xFE, 0x00, 0x00, 0x00, 0x20, 0x7F, 0xFC, 0x08, 0x20, 0x04, 0x20, 0x04, 0xA0, 0x00, 0x40, /*"等",3*/
  // 公(0) 正(1) 法(2) 治(3)
  0x00, 0x80, 0x04, 0x80, 0x04, 0x80, 0x08, 0x40, 0x08, 0x40, 0x10, 0x20, 0x20, 0x10, 0x42, 0x08,
  0x82, 0x06, 0x04, 0x00, 0x04, 0x40, 0x08, 0x20, 0x10, 0x20, 0x3F, 0xF0, 0x10, 0x10, 0x00, 0x00, /*"公",0*/
  0x00, 0x00, 0x7F, 0xFC, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x11, 0x00, 0x11, 0xF8,
  0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0xFF, 0xFE, 0x00, 0x00, /*"正",1*/
  0x00, 0x40, 0x20, 0x40, 0x10, 0x40, 0x10, 0x40, 0x87, 0xFC, 0x40, 0x40, 0x40, 0x40, 0x10, 0x40,
  0x1F, 0xFE, 0x20, 0x40, 0xE0, 0x80, 0x21, 0x00, 0x22, 0x10, 0x24, 0x08, 0x2F, 0xFC, 0x04, 0x04, /*"法",2*/
  0x00, 0x40, 0x20, 0x40, 0x10, 0x80, 0x11, 0x10, 0x82, 0x08, 0x47, 0xFC, 0x40, 0x04, 0x10, 0x00,
  0x13, 0xF8, 0x22, 0x08, 0xE2, 0x08, 0x22, 0x08, 0x22, 0x08, 0x22, 0x08, 0x23, 0xF8, 0x02, 0x08, /*"治",3*/
  // 爱(0) 国(1) 敬(2) 业(3)
  0x00, 0x08, 0x01, 0xFC, 0x7E, 0x10, 0x22, 0x10, 0x11, 0x20, 0x7F, 0xFE, 0x42, 0x02, 0x82, 0x04,
  0x7F, 0xF8, 0x04, 0x00, 0x07, 0xF0, 0x0A, 0x10, 0x11, 0x20, 0x20, 0xC0, 0x43, 0x30, 0x1C, 0x0E, /*"爱",0*/
  0x00, 0x00, 0x7F, 0xFC, 0x40, 0x04, 0x40, 0x04, 0x5F, 0xF4, 0x41, 0x04, 0x41, 0x04, 0x4F, 0xE4,
  0x41, 0x04, 0x41, 0x44, 0x41, 0x24, 0x5F, 0xF4, 0x40, 0x04, 0x40, 0x04, 0x7F, 0xFC, 0x40, 0x04, /*"国",1*/
  0x22, 0x20, 0x22, 0x20, 0xFF, 0xA0, 0x22, 0x3E, 0x40, 0x44, 0x7F, 0x44, 0x41, 0x44, 0x81, 0xA4,
  0x7D, 0x28, 0x45, 0x28, 0x45, 0x10, 0x7D, 0x10, 0x45, 0x28, 0x01, 0x28, 0x0A, 0x44, 0x04, 0x82, /*"敬",2*/
  0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0x44, 0x44, 0x24, 0x44, 0x24, 0x48, 0x14, 0x48,
  0x14, 0x50, 0x14, 0x60, 0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0xFF, 0xFE, 0x00, 0x00, /*"业",3*/
  // 诚(0) 信(1) 友(2) 善(3)
  0x00, 0x28, 0x40, 0x24, 0x20, 0x20, 0x27, 0xFE, 0x04, 0x20, 0x04, 0x20, 0xE4, 0x24, 0x27, 0xA4,
  0x24, 0xA4, 0x24, 0xA8, 0x24, 0xA8, 0x2C, 0x90, 0x36, 0x92, 0x29, 0x2A, 0x08, 0x46, 0x10, 0x82, /*"诚",0*/
  0x08, 0x40, 0x08, 0x20, 0x0B, 0xFE, 0x10, 0x00, 0x10, 0x00, 0x31, 0xFC, 0x30, 0x00, 0x50, 0x00,
  0x91, 0xFC, 0x10, 0x00, 0x10, 0x00, 0x11, 0xFC, 0x11, 0x04, 0x11, 0x04, 0x11, 0xFC, 0x11, 0x04, /*"信",1*/
  0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0xFF, 0xFE, 0x04, 0x00, 0x04, 0x00, 0x0F, 0xF0, 0x0A, 0x10,
  0x12, 0x10, 0x11, 0x20, 0x21, 0x40, 0x40, 0x80, 0x81, 0x40, 0x06, 0x20, 0x18, 0x18, 0x60, 0x06, /*"友",2*/
  0x08, 0x20, 0x04, 0x40, 0x7F, 0xFC, 0x01, 0x00, 0x3F, 0xF8, 0x01, 0x00, 0xFF, 0xFE, 0x11, 0x10,
  0x09, 0x20, 0xFF, 0xFE, 0x00, 0x00, 0x3F, 0xF8, 0x20, 0x08, 0x20, 0x08, 0x3F, 0xF8, 0x20, 0x08, /*"善",3*/
};
//==================================================================

bit HUB8_OE_ON = 1;  // HUB8OE 极性
bit AUTOLIGHT = 1;   // 自动亮度
bit WUXIU = 1;       // 是否午休
bit SECSHOW = 1;     // 秒针显示
bit YAOYAO = 0;      // 摇一摇

bit ack;            // 应答标志位
bit AutoSet = 0;    // 自动设置亮度等
bit ReadALL = 0;    // 重新读RTC，当设置超时返回，重新读取时间
bit Always = 0;     // 一直演示
bit UpDown = 0;     // 是否倒置
bit Scankey = 0;    // 可扫描键盘标识
bit ReadRTC = 0;    // 可读RTC标识
bit SaveRTC = 0;    // 可保存到芯片标识
bit SaveEPROM = 0;  // 可保存到EEPROM
bit HafSec = 0;     // 半秒改变，闪烁时显示标志
bit OneSec = 0;     // 每秒一变
bit TriSec = 0;     // 每三秒

int8_t MyTemp;                                                       // 温度校准值(char，有正负)
uchar l_tmptempshow;                                                 // 温度值显示用
uchar l_tmpgetdate[9] = { 0x01, 0x02, 0x03, 0x4, 0x7, 0x13, 0x17 };  // 取得的时间和温度 BCD秒分时日月周年17-07-13 00:00:00
uchar l_tmpdisplay[8] = { 11 };                                      // 显示的时间 8位数字格式：16-58-10，默认显示空
uchar l_tmpligth[8][2] = {
  { 0x01, STATE_OFF_MYLIGHT },  //
  { 0x04, 0 },
  { 0x07, 1 },
  { 0x08, 4 },
  { 0x10, 6 },
  { 0x15, 6 },
  { 0x18, 2 },
  { 0x22, 0 },
};
uchar l_tmpligthB[2][2] = {
  { 0x12, 1 },
  { 0x14, 4 },
};
uchar XdataDisplay[16][8];

uint16_t K = 0;  // 大于256，使用int类型
uchar N = 0;     // 进度条当前值 0-64
uchar H = 0;     // 秒指示进度条当前值 0-64
uchar F = 0;
uchar Y = 0;          // 摇一摇次数
uchar MyStyte3 = 0;   // 样式，0-三个数字；1-两个数字+温度；2-两个数字+星期；保存到EEPROM（IAP_ADDRESS_STYTE3）
uchar MySetup = 0;    // 状态：0-标准；1-调时；2-调分；3-调秒；4-调温度或星期；最大STATE_MAX_MYSTATE=3或4
uchar MyLigth = 0;    // 亮度：0-最亮，0-4（5档）								     最大STATE_MAX_MYLIGHT=5
uchar MyDisplay = 2;  // 显示状态：0-正常；1-屏保；2-演示；3-帮助；4-全亮;5-系统
uchar MySystem = 3;   // 系统：0-亮度；1-午休；2-秒针；3-摇摇
uchar I_display = 0;  // 演示显示的当前行数

int LA = 0;  //(HUB08)
int LB = 2;  //(HUB08)
int LC = 1;  //(HUB08)
int LD = 3;  //(HUB08)

int EN = 15;     //(HUB08)74HC138的使能
int LAT = 13;    //(HUB08)输出锁存
int CLK = 14;    //(HUB08)74HC595的时钟
int DATR1 = 12;  //(HUB08)红色数据1

uchar NumPlusM(uchar temp)  // 分钟加一
{
  if (temp == 0x09)
    temp = 0x10;
  else if (temp == 0x19)
    temp = 0x20;
  else if (temp == 0x29)
    temp = 0x30;
  else if (temp == 0x39)
    temp = 0x40;
  else if (temp == 0x49)
    temp = 0x50;
  else if (temp == 0x59)
    temp = 0x00;
  else
    temp++;
  return (temp);
}

void setrtctime()  // 从互联网同步时间到芯片
{
  timeClient.update();
  // The formattedDate comes with the following format: 2018-05-28T16:00:13Z
  // We need to extract date and time
  formattedDate = timeClient.getFormattedDate();
  // Serial.println(formattedDate);
  // Extract date
  int splitT = formattedDate.indexOf("T");
  dayStamp = formattedDate.substring(0, splitT);
  // Serial.print("DATE: ");
  // Serial.println(dayStamp);
  rtc.set(timeClient.getSeconds(),
          timeClient.getMinutes(),
          timeClient.getHours(),
          timeClient.getDay(),
          dayStamp.substring(8, 10).toInt(),
          dayStamp.substring(5, 7).toInt(),
          dayStamp.substring(2, 4).toInt());
  //  RTCLib::set(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
}

void getrtctime() {
  rtc.refresh();
  l_tmpgetdate[0] = rtc.second();
  l_tmpgetdate[1] = rtc.minute();
  l_tmpgetdate[2] = rtc.hour();
  l_tmpgetdate[3] = rtc.dayOfWeek();
  l_tmpgetdate[4] = rtc.day();
  l_tmpgetdate[5] = rtc.month();
  l_tmpgetdate[6] = rtc.year();
  l_tmpgetdate[7] = rtc.temp() / 100;
}

void printtime() {
  // 显示变量时间
  getrtctime();
  Serial.print("TEM DateTime: ");
  Serial.print(l_tmpgetdate[2]);
  Serial.print(":");
  Serial.print(l_tmpgetdate[1]);
  Serial.print(":");
  Serial.print(l_tmpgetdate[0]);
  Serial.print(" 20");
  Serial.print(l_tmpgetdate[6]);
  Serial.print("/");
  Serial.print(l_tmpgetdate[5]);
  Serial.print("/");
  Serial.print(l_tmpgetdate[4]);
  Serial.print(" - DOW: ");
  Serial.print(l_tmpgetdate[3]);
  Serial.print(" - Temp: ");
  Serial.print(l_tmpgetdate[7]);
  Serial.println();
  // 显示DS3231时间
  rtc.refresh();
  Serial.print("RTC DateTime: ");
  Serial.print(rtc.hour());
  Serial.print(":");
  Serial.print(rtc.minute());
  Serial.print(":");
  Serial.print(rtc.second());
  Serial.print(" 20");
  Serial.print(rtc.year());
  Serial.print("/");
  Serial.print(rtc.month());
  Serial.print("/");
  Serial.print(rtc.day());
  Serial.print(" - DOW: ");
  Serial.print(rtc.dayOfWeek());
  Serial.print(" - Temp: ");
  Serial.print(rtc.temp() / 100);
  Serial.println();
  // 显示互联网时间
  timeClient.update();
  formattedDate = timeClient.getFormattedDate();
  int splitT = formattedDate.indexOf("T");
  dayStamp = formattedDate.substring(0, splitT);
  Serial.print("NTP DateTime: ");
  Serial.print(timeClient.getFormattedTime());
  Serial.print(" ");
  Serial.print(dayStamp.substring(0, 4));
  Serial.print("/");
  Serial.print(dayStamp.substring(5, 7));
  Serial.print("/");
  Serial.print(dayStamp.substring(8, 10));
  Serial.print(" - DOW: ");
  Serial.println(timeClient.getDay());
}

void listserial() {
  // 监控串口
  if (Serial.available()) {                      // 当串口接收到信息后
    Serial.println("Serial Data Available...");  // 通过串口监视器通知用户

    String serialData = Serial.readString();  // 将接收到的信息使用readString()存储于serialData变量
    Serial.print("Received Serial Data: ");   // 然后通过串口监视器输出serialData变量内容
    Serial.println(serialData);               // 以便查看serialData变量的信息

    if (serialData == "help") {
      Serial.println("---- help ----");
      Serial.println("1.reset: reset wifi and reboot.");
      Serial.println("2.ssid: show ssid.");
      Serial.println("3.ip: show ip.");
      Serial.println("4.mac: show mac.");
      Serial.println("5.host: show host mac.");
      Serial.println("6.rssi: show wifi signal strength.");
      Serial.println("7.setrtc: set ds3231 from ntp.");
      Serial.println("8.timer: set or unset 1s timer.");
      Serial.println("0.dome order.");
      Serial.println("--------------");
    } else if (serialData == "reset") {
      analogWrite(ledPin, 255);
      Serial.println("ESP8266 WiFi Settings Cleared!");
      WiFiManager wifiManager;
      wifiManager.resetSettings();
      // ESP.reset(); // demo中例子，但是不能用
      ESP.eraseConfig();
      Serial.println("System restart...");
      delay(5000);
      resetFunc();
    } else if (serialData == "ssid") {
      Serial.print("ESP8266 Connected to ");
      Serial.println(WiFi.SSID());
    } else if (serialData == "ip") {
      Serial.print("IP address:\t");
      Serial.println(WiFi.localIP());
    } else if (serialData == "mac") {
      byte mac[6];
      WiFi.macAddress(mac);
      char buf[20];
      sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
      Serial.print("MAC address: ");
      Serial.println(buf);
    } else if (serialData == "host") {
      uint8_t *bssid = WiFi.BSSID();
      Serial.print("Host address: ");
      for (byte i = 0; i < 6; i++) {
        Serial.print(*bssid++, HEX);
        if (i < 5)
          Serial.print(":");
      }
      Serial.println("");
    } else if (serialData == "rssi") {
      long rssi = WiFi.RSSI();
      Serial.print("Signal strength (RSSI): ");
      Serial.println(rssi);
    } else if (serialData == "setrtc") {
      // 停止定时器
      timer1.detach();
      Serial.println("Stop timer");

      timeClient.update();
      rtc.set(timeClient.getSeconds(),
              timeClient.getMinutes(),
              timeClient.getHours(),
              timeClient.getDay(),
              dayStamp.substring(8, 10).toInt(),
              dayStamp.substring(5, 7).toInt(),
              dayStamp.substring(2, 4).toInt());
      //  RTCLib::set(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
      Serial.println("Set ds3231 from ntp.");
    } else if (serialData == "timer") {
      if (timer1.active()) {
        timer1.detach();
        Serial.println("Stop timer");
      } else {
        timer1.attach(1, flash);
        Serial.println("Start timer");
      }
    } else if (serialData == "setrtctime") {
      setrtctime();
      Serial.println("Set RTC from intenel.");
    } else if (serialData == "printtime") {
      printtime();
      Serial.println("Show TEM time.");
    } else {
      Serial.println("Not available Order!");
    }
  }
}

void flash()  // 10ms定时
{
  static uchar j = 0, n = 0;  // 静态变量，下次还能用

  Scankey = 1;  // 10ms 扫描键盘一次，使用标志位控制
  ReadRTC = 1;  // 可以读RTC

  F++;          // 全局变量，半秒闪烁标识
  if (F >= 50)  // 50*10=500ms，闪烁，使用标志位判断
  {
    F = 0;
    HafSec = !HafSec;

    j++;
    if (j >= 2) {  // 50*10*2=1000ms，1秒定时，使用标志位判断
      j = 0;
      OneSec = !OneSec;

      if (MySetup == 3) {  // 调整秒状态，秒自动每秒加一，不从RTC中取得，不自动加分
        l_tmpgetdate[0] = NumPlusM(l_tmpgetdate[0]);
      }

      n++;
      if (n >= 3) {  // 3s定时
        n = 0;
        TriSec = 1;

        if (MyDisplay == 3) {  // 3帮助
          I_display++;

          if (I_display > (STATE_MAX_MYHELP)) {
            I_display = 0;
            MyDisplay = 0;
          }
        }

        if (MyDisplay == 2) {  // 2演示状态
          I_display++;

          if (Always) {
            if (I_display > (STATE_MAX_MYALWAYS)) {
              I_display = 0;  // 从头开始显示演示
            }
          } else {
            if (I_display > (STATE_MAX_MYDISPLAY)) {
              I_display = 0;
              MyDisplay = 0;  // 只显示一次演示
              ReadALL = 1;
              AutoSet = 1;  // 第一次显示时间之前，自动设置时间和亮度
            }
          }
        }

        if (MyDisplay == 0) {
          if (Y >= 4 && YAOYAO) {
            I_display = 13;  // 从第13条开始
            MyDisplay = 3;   // 显示一次帮助
          }
        }

        Y = 0;  // 每3秒，清一次摇一摇
      }
    }
  }

  K++;              // 全局变量，10秒恢复状态标识，不自动保存
  if (K >= 1000) {  // 1000*10=10000ms,10秒清状态回显示状态，K必须为int类型
    K = 0;
    if (MySetup != 0) {
      MySetup = 0;
      ReadALL = 1;  // 重新读RTC，重新显示
    }
  }
}

void SetDisplay(uchar I_mydis, uchar I_dis) {
  uchar num, m, u, t;
  uchar d0, d1, d2, d3, d4, d5, d6, d7;

  if (!I_mydis) {

    if (!MyStyte3) {

      l_tmpdisplay[0] = l_tmpgetdate[2] / 16;
      l_tmpdisplay[1] = l_tmpgetdate[2] & 0x0f;
      l_tmpdisplay[2] = 10;
      l_tmpdisplay[3] = l_tmpgetdate[1] / 16;
      l_tmpdisplay[4] = l_tmpgetdate[1] & 0x0f;
      l_tmpdisplay[5] = 10;
      l_tmpdisplay[6] = l_tmpgetdate[0] / 16;
      l_tmpdisplay[7] = l_tmpgetdate[0] & 0x0f;

      if (HafSec & (MySetup == 1)) {
        l_tmpdisplay[0] = 11;
        l_tmpdisplay[1] = 11;
      }

      if (HafSec & (MySetup == 2)) {
        l_tmpdisplay[3] = 11;
        l_tmpdisplay[4] = 11;
      }

      if (HafSec & (MySetup == 3)) {
        l_tmpdisplay[6] = 11;
        l_tmpdisplay[7] = 11;
      }
    } else {                                     // 显示两个数字 + 温度 or + 星期
      l_tmptempshow = l_tmpgetdate[7] + MyTemp;  // 温度在一定范围
      if (l_tmptempshow < 0)
        MyTemp = 0;
      if (l_tmptempshow > 50)
        MyTemp = 0;

      if (MySetup == 0) {
        l_tmpdisplay[0] = l_tmpgetdate[2] / 16;
        l_tmpdisplay[1] = l_tmpgetdate[2] & 0x0f;

        if (OneSec) {  // 正常状态，1s闪烁冒号
          l_tmpdisplay[2] = 11;
        } else {
          l_tmpdisplay[2] = 10;
        }
        l_tmpdisplay[3] = l_tmpgetdate[1] / 16;
        l_tmpdisplay[4] = l_tmpgetdate[1] & 0x0f;
        l_tmpdisplay[5] = 11;
        l_tmpdisplay[6] = l_tmptempshow / 10;
        l_tmpdisplay[7] = l_tmptempshow % 10;
      } else if (MySetup == 1) {

        if (HafSec) {
          l_tmpdisplay[0] = 11;
          l_tmpdisplay[1] = 11;
        } else {
          l_tmpdisplay[0] = l_tmpgetdate[2] / 16;
          l_tmpdisplay[1] = l_tmpgetdate[2] & 0x0f;
        }
        l_tmpdisplay[2] = 10;
        l_tmpdisplay[3] = l_tmpgetdate[1] / 16;
        l_tmpdisplay[4] = l_tmpgetdate[1] & 0x0f;
        l_tmpdisplay[5] = 11;
        l_tmpdisplay[6] = l_tmptempshow / 10;
        l_tmpdisplay[7] = l_tmptempshow % 10;
      } else if (MySetup == 2) {
        l_tmpdisplay[0] = l_tmpgetdate[2] / 16;
        l_tmpdisplay[1] = l_tmpgetdate[2] & 0x0f;
        l_tmpdisplay[2] = 10;

        if (HafSec) {
          l_tmpdisplay[3] = 11;
          l_tmpdisplay[4] = 11;
        } else {
          l_tmpdisplay[3] = l_tmpgetdate[1] / 16;
          l_tmpdisplay[4] = l_tmpgetdate[1] & 0x0f;
        }
        l_tmpdisplay[5] = 11;
        l_tmpdisplay[6] = l_tmptempshow / 10;
        l_tmpdisplay[7] = l_tmptempshow % 10;
      } else if (MySetup == 3) {
        l_tmpdisplay[0] = 11;
        l_tmpdisplay[1] = 11;
        l_tmpdisplay[2] = 10;

        if (HafSec) {
          l_tmpdisplay[3] = 11;
          l_tmpdisplay[4] = 11;
        } else {
          l_tmpdisplay[3] = l_tmpgetdate[0] / 16;
          l_tmpdisplay[4] = l_tmpgetdate[0] & 0x0f;
        }
        l_tmpdisplay[5] = 11;
        l_tmpdisplay[6] = l_tmptempshow / 10;
        l_tmpdisplay[7] = l_tmptempshow % 10;
      } else if (MySetup == 4) {
        l_tmpdisplay[0] = l_tmpgetdate[2] / 16;
        l_tmpdisplay[1] = l_tmpgetdate[2] & 0x0f;
        l_tmpdisplay[2] = 10;
        l_tmpdisplay[3] = l_tmpgetdate[1] / 16;
        l_tmpdisplay[4] = l_tmpgetdate[1] & 0x0f;
        l_tmpdisplay[5] = 11;

        if (HafSec) {
          l_tmpdisplay[6] = 11;
          l_tmpdisplay[7] = 11;
        } else {
          l_tmpdisplay[6] = l_tmptempshow / 10;
          l_tmpdisplay[7] = l_tmptempshow % 10;
        }
      }
    }
  }

  for (num = 0; num < 16; num++) {
    if (!I_mydis) {  // 正常显示

      if (num == 15) {  // 根据N值，在15行显示进度条

        XdataDisplay[num][0] = 0x00;
        XdataDisplay[num][1] = 0x00;
        XdataDisplay[num][2] = 0x00;
        XdataDisplay[num][3] = 0x00;
        XdataDisplay[num][4] = 0x00;
        XdataDisplay[num][5] = 0x00;
        XdataDisplay[num][6] = 0x00;
        XdataDisplay[num][7] = 0x00;

        if (N > 0 && N < 64) {  // 优先显示进度条
          m = N / 8;
          u = N % 8;
          switch (u) {
            case 0:
              t = 0x00;
              break;
            case 1:
              t = 0x80;
              break;
            case 2:
              t = 0xc0;
              break;
            case 3:
              t = 0xe0;
              break;
            case 4:
              t = 0xf0;
              break;
            case 5:
              t = 0xf8;
              break;
            case 6:
              t = 0xfc;
              break;
            case 7:
              t = 0xfe;
              break;
          }

          switch (m) {
            case 0:
              XdataDisplay[num][0] = t;
              break;
            case 1:
              XdataDisplay[num][0] = 0xff;
              XdataDisplay[num][1] = t;
              break;
            case 2:
              XdataDisplay[num][0] = 0xff;
              XdataDisplay[num][1] = 0xff;
              XdataDisplay[num][2] = t;
              break;
            case 3:
              XdataDisplay[num][0] = 0xff;
              XdataDisplay[num][1] = 0xff;
              XdataDisplay[num][2] = 0xff;
              XdataDisplay[num][3] = t;
              break;
            case 4:
              XdataDisplay[num][0] = 0xff;
              XdataDisplay[num][1] = 0xff;
              XdataDisplay[num][2] = 0xff;
              XdataDisplay[num][3] = 0xff;
              XdataDisplay[num][4] = t;
              break;
            case 5:
              XdataDisplay[num][0] = 0xff;
              XdataDisplay[num][1] = 0xff;
              XdataDisplay[num][2] = 0xff;
              XdataDisplay[num][3] = 0xff;
              XdataDisplay[num][4] = 0xff;
              XdataDisplay[num][5] = t;
              break;
            case 6:
              XdataDisplay[num][0] = 0xff;
              XdataDisplay[num][1] = 0xff;
              XdataDisplay[num][2] = 0xff;
              XdataDisplay[num][3] = 0xff;
              XdataDisplay[num][4] = 0xff;
              XdataDisplay[num][5] = 0xff;
              XdataDisplay[num][6] = t;
              break;
            case 7:
              XdataDisplay[num][0] = 0xff;
              XdataDisplay[num][1] = 0xff;
              XdataDisplay[num][2] = 0xff;
              XdataDisplay[num][3] = 0xff;
              XdataDisplay[num][4] = 0xff;
              XdataDisplay[num][5] = 0xff;
              XdataDisplay[num][6] = 0xff;
              XdataDisplay[num][7] = t;
              break;
          }
        } else if (H > 0 && H < 64) {  // 显示秒指针
          m = H / 8;
          u = H % 8;
          switch (u) {
            case 0:
              t = 0x80;
              break;
            case 1:
              t = 0xc0;
              break;
            case 2:
              t = 0x60;
              break;
            case 3:
              t = 0x30;
              break;
            case 4:
              t = 0x18;
              break;
            case 5:
              t = 0x0c;
              break;
            case 6:
              t = 0x06;
              break;
            case 7:
              t = 0x03;
              break;
          }

          switch (m) {
            case 0:
              XdataDisplay[num][0] = t & 0x7f;
              break;
            case 1:
              if (u == 0)
                XdataDisplay[num][0] = 0x01;
              XdataDisplay[num][1] = t;
              break;
            case 2:
              if (u == 0)
                XdataDisplay[num][1] = 0x01;
              XdataDisplay[num][2] = t;
              break;
            case 3:
              if (u == 0)
                XdataDisplay[num][2] = 0x01;
              XdataDisplay[num][3] = t;
              break;
            case 4:
              if (u == 0)
                XdataDisplay[num][3] = 0x01;
              XdataDisplay[num][4] = t;
              break;
            case 5:
              if (u == 0)
                XdataDisplay[num][4] = 0x01;
              XdataDisplay[num][5] = t;
              break;
            case 6:
              if (u == 0)
                XdataDisplay[num][5] = 0x01;
              XdataDisplay[num][6] = t;
              break;
            case 7:
              if (u == 0)
                XdataDisplay[num][6] = 0x01;
              XdataDisplay[num][7] = t;
              break;
          }
        }
      } else {

        d0 = Tablehub[num + 16 * l_tmpdisplay[0]];
        d1 = Tablehub[num + 16 * l_tmpdisplay[1]];
        d2 = Tablehub[num + 16 * l_tmpdisplay[2]];
        d3 = Tablehub[num + 16 * l_tmpdisplay[3]];
        d4 = Tablehub[num + 16 * l_tmpdisplay[4]];
        d5 = Tablehub[num + 16 * l_tmpdisplay[5]];
        d6 = Tablehub[num + 16 * l_tmpdisplay[6]];
        d7 = Tablehub[num + 16 * l_tmpdisplay[7]];

        XdataDisplay[num][0] = d0 >> 2;  // 左边空两列
        XdataDisplay[num][1] = d0 << 6 | d1 >> 2;
        XdataDisplay[num][2] = d1 << 6 | d2 >> 2;
        XdataDisplay[num][3] = d3;
        XdataDisplay[num][4] = d4;

        if (!MyStyte3) {
          XdataDisplay[num][5] = d5 & 0xfc | d6 >> 6;
          XdataDisplay[num][6] = d6 << 2 | d7 >> 6;
          XdataDisplay[num][7] = d7 << 2;  // 右边空两列
        } else if (MyStyte3 == 1) {
          XdataDisplay[num][5] = TableTempS[num + 16 * l_tmpdisplay[6]];  // 温度十位
          XdataDisplay[num][6] = TableTempG[num + 16 * l_tmpdisplay[7]];  // 温度个位
          XdataDisplay[num][7] = TableTempG[num + 16 * 10];               // 温度符号c
        } else if (MyStyte3 == 2) {
          XdataDisplay[num][5] = 0x00;

          if (MySetup == 4 && HafSec) {  // 显示星期，当设置状态4时，每半秒闪烁星期
            XdataDisplay[num][6] = 0x00;
            XdataDisplay[num][7] = 0x00;
          } else {
            XdataDisplay[num][6] = TableWeek[num * 2 + 0 + (l_tmpgetdate[3] - 1) * 32];
            XdataDisplay[num][7] = TableWeek[num * 2 + 1 + (l_tmpgetdate[3] - 1) * 32];
          }
        }
      }
    } else if (I_mydis == 1) {  // 屏保
      XdataDisplay[num][0] = 0x00;
      XdataDisplay[num][1] = 0x00;
      XdataDisplay[num][2] = 0x00;
      XdataDisplay[num][3] = 0x00;
      XdataDisplay[num][4] = 0x00;
      XdataDisplay[num][5] = 0x00;
      XdataDisplay[num][6] = 0x00;
      XdataDisplay[num][7] = 0x00;
    } else if (I_mydis == 4) {  // 全亮
      XdataDisplay[num][0] = 0xff;
      XdataDisplay[num][1] = 0xff;
      XdataDisplay[num][2] = 0xff;
      XdataDisplay[num][3] = 0xff;
      XdataDisplay[num][4] = 0xff;
      XdataDisplay[num][5] = 0xff;
      XdataDisplay[num][6] = 0xff;
      XdataDisplay[num][7] = 0xff;
    } else {  // if(I_mydis == 2 || I_mydis == 3 || I_mydis == 5){			// 演示或帮助或系统设置，
      if (I_mydis == 5) {
        if (MySystem == 0) {
          if (AUTOLIGHT) {
            I_dis = 5;
          } else {
            I_dis = 6;
          }
        } else if (MySystem == 1) {
          if (WUXIU) {
            I_dis = 7;
          } else {
            I_dis = 8;
          }
        } else if (MySystem == 2) {
          if (SECSHOW) {
            I_dis = 9;
          } else {
            I_dis = 10;
          }
        } else if (MySystem == 3) {
          if (YAOYAO) {
            I_dis = 11;
          } else {
            I_dis = 12;
          }
        }
      }
      XdataDisplay[num][0] = TableYanShi[num * 2 + 0 + I_dis * 128];
      XdataDisplay[num][1] = TableYanShi[num * 2 + 1 + I_dis * 128];
      XdataDisplay[num][2] = TableYanShi[num * 2 + 0 + 32 + I_dis * 128];
      XdataDisplay[num][3] = TableYanShi[num * 2 + 1 + 32 + I_dis * 128];
      XdataDisplay[num][4] = TableYanShi[num * 2 + 0 + 64 + I_dis * 128];
      XdataDisplay[num][5] = TableYanShi[num * 2 + 1 + 64 + I_dis * 128];
      XdataDisplay[num][6] = TableYanShi[num * 2 + 0 + 96 + I_dis * 128];
      XdataDisplay[num][7] = TableYanShi[num * 2 + 1 + 96 + I_dis * 128];
    }
  }
}

/******************************************************************/
/*                 74HC595串行数据输入                            */
/******************************************************************/
void SendDateR1(uchar DataR1, uchar num) {
  unsigned char i;
  for (i = num; i > 0; i--) {
    CLK = 0;
    DATR1 = DataR1 & 0x80;
    CLK = 1;
    DataR1 <<= 1;
  }
}
void SendDateR1F(uchar DataR1, uchar num) {  // 反向读取，上下倒置使用
  unsigned char i;
  for (i = num; i > 0; i--) {
    CLK = 0;
    DATR1 = DataR1 & 0x01;
    CLK = 1;
    DataR1 >>= 1;
  }
}

/******************************************************************/
/*                 自动设置时间，及亮度                           */
/******************************************************************/
void AutoSetMyLigth(void) {
  if (AUTOLIGHT) {
    MyLigth = STATE_MIN_MYLIGHT;

    for (uchar j = 0; j < 8; j++) {  // 根据当前小时时间，取得亮度值，时间必须按照大小排序
      if ((l_tmpgetdate[2] >= l_tmpligth[j][0]))
        MyLigth = l_tmpligth[j][1];
    }
  }

  if (MyLigth > STATE_MAX_MYLIGHT) {
    MyLigth = STATE_MAX_MYLIGHT;
  }
}

void setup() {
  // Serial.begin(115200);
  // pinMode(ledPin, OUTPUT); // 呼吸灯
  // analogWrite(ledPin, 120);

  WiFiManager wifiManager;
  if (!wifiManager.autoConnect("ESPAutoWiFi")) {
    // reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(1000);
  }

  URTCLIB_WIRE.begin();  // D2(GPIO5) and D1(GPIO4) on ESP8266
  rtc.set_rtc_address(0x68);
  rtc.set_model(URTCLIB_MODEL_DS3231);

  MyStyte3 = 0;
  MySetup = 0;
  MyDisplay = 2;  // 开机演示
  I_display = 0;  // 演示显示第一行

  SetDisplay(MyDisplay, I_display);

  timer1.attach_ms(10, flash);  // 10ms定时器开启
}

void loop() {
  uchar num, j;
  bit b;

  // // 呼吸灯
  // for (int a = 0; a <= 255; a++)
  // {
  //   analogWrite(ledPin, a);
  //   delay(5);
  // }
  // for (int a = 255; a >= 0; a--)
  // {
  //   analogWrite(ledPin, a);
  //   delay(5);
  // }
  // // 监控串口
  // listserial();
  // delay(500);

  for (num = 0; num < 16; num++) {
    if (!UpDown) {
      SendDateR1(~XdataDisplay[num][0], 8);
      SendDateR1(~XdataDisplay[num][1], 8);
      SendDateR1(~XdataDisplay[num][2], 8);
      SendDateR1(~XdataDisplay[num][3], 8);
      SendDateR1(~XdataDisplay[num][4], 8);
      SendDateR1(~XdataDisplay[num][5], 8);
      SendDateR1(~XdataDisplay[num][6], 8);
      SendDateR1(~XdataDisplay[num][7], 8);
    } else {
      SendDateR1F(~XdataDisplay[16 - 1 - num][7], 8);
      SendDateR1F(~XdataDisplay[16 - 1 - num][6], 8);
      SendDateR1F(~XdataDisplay[16 - 1 - num][5], 8);
      SendDateR1F(~XdataDisplay[16 - 1 - num][4], 8);
      SendDateR1F(~XdataDisplay[16 - 1 - num][3], 8);
      SendDateR1F(~XdataDisplay[16 - 1 - num][2], 8);
      SendDateR1F(~XdataDisplay[16 - 1 - num][1], 8);
      SendDateR1F(~XdataDisplay[16 - 1 - num][0], 8);
    }
    EN = !HUB8_OE_ON;  // 暂不显示，防止以下串行输出闪烁

    LAT = 0;
    LA = num & 0x01;
    LB = num & 0x02;
    LC = num & 0x04;
    LD = num & 0x08;
    LAT = 1;  // 输出锁存 LAT:0->1

    EN = HUB8_OE_ON;  // 显示，输出到HUB08板卡

    delay(MyLigth * 20);  // 延时

    if (MyLigth == STATE_MAX_MYLIGHT)
      EN = HUB8_OE_ON;  // 最亮，保持输出显示
    else
      EN = !HUB8_OE_ON;  // 时间到，停止输出显示
  }

  if (ReadALL) {  // 全部读一次时间，包括小时分钟和秒，当按键操作超时返回，可能已经修改了显示，但不保存，需要执行
    ReadALL = 0;

    getrtctime();

    if (AutoSet) {  // 自动设置时间和亮度，在第一次显示时间之前操作，两个入口，显示完演示定时结束和主动按S键结束
      AutoSet = 0;  // 设置了AutoSet，前面必须运行Read_RTC()，故前必须设置 ReadALL = 1;

      AutoSetMyLigth();
    }
  }

  if (MyDisplay > 1) {
    if (MyDisplay == 5) {  // 系统设置，实时显示
      SetDisplay(MyDisplay, I_display);
    } else if (TriSec) {  // 演示或帮助状态2 3，每三秒换显示，主要是文本
      TriSec = 0;

      SetDisplay(MyDisplay, I_display);
    }
    return;  // 不再执行下面语句，退出
  }

  if (MyStyte3 == 1) {  // 显示温度状态，每三秒，读一次温度值
    if (TriSec) {
      TriSec = 0;
      getrtctime();
      // l_tmpgetdate[8] = I2C_read_random(DS3231_Address, DS3231_TEML);
      // l_tmpgetdate[7] = I2C_read_random(DS3231_Address, DS3231_TEMH);
    }
  }

  if (!ReadRTC)  // 没到每10ms，退出
  {
    return;
  }
  ReadRTC = 0;

  if (SaveRTC) {  // 可以保存设置时，保存，并清除标识
    SaveRTC = 0;

    timer1.detach();
    setrtctime();
    // Save_RTC(); // 写操作不能在子程序中运行，否则不能生效，原因（可能是写操作时间长，被中断打断导致错误）
    timer1.attach_ms(10, flash);
  } else {

    if (!MySetup) {
      getrtctime();
      // l_tmpgetdate[0] = I2C_read_random(DS3231_Address, DS3231_SECOND); // 取秒
      if (MyStyte3 && SECSHOW) {
        H = l_tmpgetdate[0] / 16 * 10 + l_tmpgetdate[0] % 16 + 2;  // 设置秒进度条 2-62
      } else {
        H = 0;
      }

      if (l_tmpgetdate[0] == 0x00) {  // 状态0时，当00秒时，从RTC取分钟（1秒内，只取一次）
        if (b) {                      // 第一次进入，肯定是b=1，
          getrtctime();
          // l_tmpgetdate[1] = I2C_read_random(DS3231_Address, DS3231_MINUTE);

          if (l_tmpgetdate[1] == 0x00) {  // 状态0时，当00分时，从RTC取小时和星期（1分内，只取一次）
            getrtctime();
            // l_tmpgetdate[2] = I2C_read_random(DS3231_Address, DS3231_HOUR);
            // l_tmpgetdate[3] = I2C_read_random(DS3231_Address, DS3231_WEEK);

            if (AUTOLIGHT) {
              for (j = 0; j < 8; j++) {  // 比较时间是否需要改变亮度，有8个时间段需要比较，只比较小时，分钟和秒必须为0
                if (l_tmpgetdate[2] == l_tmpligth[j][0]) {
                  if (l_tmpligth[j][1] == STATE_OFF_MYLIGHT) {  // l_tmpligth[j][1] = 99
                    MyDisplay = 1;                              // 不亮，屏保
                    MyLigth = STATE_MIN_MYLIGHT;                // 最低亮度
                  } else {
                    MyDisplay = 0;  // 正常显示数字时钟
                    MyLigth = l_tmpligth[j][1];
                  }
                }
              }
            }
          } else if (l_tmpgetdate[1] == 0x30) {  // 半小时，调整亮度
            if (AUTOLIGHT && WUXIU) {
              for (j = 0; j < 2; j++) {
                if (l_tmpgetdate[2] == l_tmpligthB[j][0])
                  MyLigth = l_tmpligthB[j][1];
              }
            }
          }
        }
        b = 0;  // 只执行一次，除非过了00秒
      } else {
        b = 1;
      }
    }

    SetDisplay(MyDisplay, 0);  // MyDisplay = 0，1
  }
}
